<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;
use app\admin\command\tcp;

/**
 * 测试管理
 *
 * @icon fa fa-circle-o
 */
class Test extends Backend
{

    /**
     * Test模型对象
     * @var \app\admin\model\Test
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Test;
        $this->view->assign("weekList", $this->model->getWeekList());
        $this->view->assign("flagList", $this->model->getFlagList());
        $this->view->assign("genderdataList", $this->model->getGenderdataList());
        $this->view->assign("hobbydataList", $this->model->getHobbydataList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("stateList", $this->model->getStateList());
    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

  public function index()
    {
        die;
        $client = stream_socket_client('tcp://0.0.0.0:35001', $errno, $errmsg, 1);
        fwrite($client, "7E00010399570D\n");
        echo fread($client, 8192);
        die;
        
        
       
        // echo 2;die;
     
        $add = 1;
        $cmd = 3;
        $data = 99;
        $hex1 = (dechex(hexdec($add) + hexdec($cmd) + hexdec($data)));



dump($hex1);

        $add = 0;
        $cmd = 5;
        $data = 4;
        $hex1 = hexdec(dechex(hexdec($add) + hexdec($cmd) + hexdec($data)));
        dump(hexdec($hex1));
        die;
        
        
       
        $command="7E 00 01 05 01 07 0D";
        
// 7E 00 09 05 00 14 0D  合闸
// 7E 00 09 05 01 15 0D  分闸
        try {
            // hex2bin
            $sendStr = hex2bin(str_replace(' ', '', $command));
            
            var_dump($sendStr);die;
            $res = tcp::sendToAll($sendStr);
            dump($res);
        } catch (\Exception $exception) {
            return false;
        }
    }
}
